package com.ynkbny.web.controller;

import com.ynkbny.domain.mongo.Article;
import com.ynkbny.domain.mongo.SbLog;
import com.ynkbny.util.MongoUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文章操作-控制层（测试MongoUtil工具类用的）
 *
 * @author : juzipi123
 * @date : 2023-7-20
 */
@RestController
@RequestMapping("/article")
@Api(tags = "文章操作")
public class ArticleController {

    @Resource
    private MongoUtil mongoUtil;

    @PostMapping("/create")
    @ApiOperation("创建文章")
    public String create(@RequestBody Article article) {
        int result = mongoUtil.save(article);
        if (result > 0) {
            return "文章创建成功";
        } else {
            return "文章创建失败";
        }
    }


    @PostMapping("/delete")
    @ApiOperation("批量删除文章")
    public String delete(@RequestParam("ids") List<String> ids) {
        int count = mongoUtil.remove("id",ids, Article.class);
        if (count > 0) {
            return "删除了" + count + "篇文章";
        } else {
            return "删除文章失败";
        }
    }


    @PostMapping("/list")
    @ApiOperation("查询1")
    public List<Article> list(String content) {
        return mongoUtil.find("content", content, Article.class);
    }

    /**
     * enterpriseCode 统一社会信用代码
     * statDate 数据统计时间
     * dataCode 上传数据项编码
     * responseCode 成功/失败
     */
    @PostMapping("/list3")
    @ApiOperation("查询3")
    public List<SbLog> list3(String enterpriseCode, String statDate, String dataCode, Integer responseCode) {
        return mongoUtil.find3(enterpriseCode, statDate, dataCode, responseCode, SbLog.class);
    }

}
